package java_generics.bounded_type_parameters;

//determines the largest of two Comparable objects

public class MaximumTest {
	
	// We can not use > to compare two Generics
	
	// returns Maximum of two input parameters
	/*public static <T> T max(T x, T y) {
		//Error: The operator > is undefined
		// for the argument type(s) T, T
		if (x > y) {
			return x;
		} else {
			return y;
		}
	}*/

	// How ever we can use Compareable interface compareTo
	// determines the largest of two Comparable objects
	
	public static <T extends Comparable<T>>
								T max(T x, T y) {
		if (x.compareTo(y) > 0) {
			return x;
		} else {
			return y;
		}
	}

	public static void main(String args[]) {
		
		max(10, 20); // 20
		max(5.3, 10.2); // 10.2
		max("Mango", "Apple"); // Mango
		
	}
}
